{"ast":null,"code":"import _slicedToArray from\"/Users/poppie/Desktop/development/messenger/app/frontend/node_modules/@babel/runtime/helpers/esm/slicedToArray.js\";import React from\"react\";import{Dialogs as DialogList}from\"../components/\";import{getOtherUserForNotMultiChat}from\"../utils/Membership\";import{observer}from\"mobx-react-lite\";import{Context}from\"../index\";import{getUserName}from\"../utils/User\";import{jsx as _jsx}from\"react/jsx-runtime\";var Dialogs=function Dialogs(){var _React$useContext=React.useContext(Context),store=_React$useContext.store;var _React$useState=React.useState({items:[]}),_React$useState2=_slicedToArray(_React$useState,2),chatsList=_React$useState2[0],setChatsList=_React$useState2[1];var _React$useState3=React.useState(''),_React$useState4=_slicedToArray(_React$useState3,2),inputValue=_React$useState4[0],setInputValue=_React$useState4[1];var _React$useState5=React.useState(chatsList.items),_React$useState6=_slicedToArray(_React$useState5,2),sort=_React$useState6[0],setSort=_React$useState6[1];var _React$useState7=React.useState(false),_React$useState8=_slicedToArray(_React$useState7,2),onload=_React$useState8[0],setOnload=_React$useState8[1];React.useEffect(function(){store.getChatsFromAPI().then(function(){return setOnload(true);});// eslint-disable-next-line react-hooks/exhaustive-deps\n},[]);React.useEffect(function(){setChatsList(store.getChats());chatsList.items&&setSort(chatsList.items);// eslint-disable-next-line react-hooks/exhaustive-deps\n},[store.getChats()]);var onChangeInput=function onChangeInput(){var value=arguments.length>0&&arguments[0]!==undefined?arguments[0]:'';if(chatsList.items.length>0){setSort(chatsList.items.filter(function(dialog){return dialog.multiChat?dialog.name.toLowerCase().indexOf(value.toLowerCase())>=0:getUserName(dialog.membership?getOtherUserForNotMultiChat(store,dialog.membership):store.getProfile()).toLowerCase().indexOf(value.toLowerCase())>=0;}));}setInputValue(value);};if(onload){return/*#__PURE__*/_jsx(DialogList,{chatsList:{items:sort},onSearch:onChangeInput,inputValue:inputValue});}else{return/*#__PURE__*/_jsx(DialogList,{chatsList:{items:[]},onSearch:onChangeInput,inputValue:inputValue});}};export default observer(Dialogs);","map":{"version":3,"names":["React","Dialogs","DialogList","getOtherUserForNotMultiChat","observer","Context","getUserName","useContext","store","useState","items","chatsList","setChatsList","inputValue","setInputValue","sort","setSort","onload","setOnload","useEffect","getChatsFromAPI","then","getChats","onChangeInput","value","length","filter","dialog","multiChat","name","toLowerCase","indexOf","membership","getProfile"],"sources":["/Users/poppie/Desktop/development/messenger/app/frontend/src/containers/Dialogs.tsx"],"sourcesContent":["import React from \"react\";\nimport {Dialogs as DialogList} from \"../components/\";\nimport {ChatsListResponse} from \"../models/response/ChatsListResponse\";\nimport {getOtherUserForNotMultiChat} from \"../utils/Membership\";\nimport {observer} from \"mobx-react-lite\";\nimport {Context} from \"../index\";\nimport {getUserName} from \"../utils/User\";\nimport {ChatsListItem} from \"../models/response/ChatsListItem\";\n\nconst Dialogs:React.FC = () => {\n    const {store} = React.useContext(Context);\n    const [chatsList, setChatsList] = React.useState<ChatsListResponse>({items: []});\n    const [inputValue, setInputValue] = React.useState<string>('');\n    const [sort, setSort] = React.useState(chatsList.items);\n    const [onload, setOnload] = React.useState<boolean>(false);\n\n    React.useEffect(() => {\n        store.getChatsFromAPI().then(() =>\n            setOnload(true)\n        );\n        // eslint-disable-next-line react-hooks/exhaustive-deps\n    }, []);\n\n    React.useEffect(() => {\n        setChatsList(store.getChats());\n        chatsList.items && setSort(chatsList.items);\n        // eslint-disable-next-line react-hooks/exhaustive-deps\n    }, [store.getChats()]);\n\n    const onChangeInput = (value: string = '') => {\n        if (chatsList.items.length > 0) {\n            setSort(\n                chatsList.items.filter(\n                    (dialog: ChatsListItem) => (\n                        (dialog.multiChat)? dialog.name.toLowerCase().indexOf(value.toLowerCase()) >= 0:\n                            getUserName(\n                                dialog.membership?\n                                    getOtherUserForNotMultiChat(store, dialog.membership):\n                                    store.getProfile()\n                            ).toLowerCase().indexOf(value.toLowerCase()) >= 0\n                    )\n                )\n            );\n        }\n\n        setInputValue(value);\n    };\n\n    if (onload) {\n        return <DialogList\n            chatsList={{items: sort}}\n            onSearch={onChangeInput}\n            inputValue={inputValue}\n        />;\n    } else {\n        return <DialogList\n            chatsList={{items: []}}\n            onSearch={onChangeInput}\n            inputValue={inputValue}\n        />;\n    }\n};\n\nexport default observer(Dialogs);"],"mappings":"8IAAA,MAAOA,MAAK,KAAM,OAAO,CACzB,OAAQC,OAAO,GAAIC,WAAU,KAAO,gBAAgB,CAEpD,OAAQC,2BAA2B,KAAO,qBAAqB,CAC/D,OAAQC,QAAQ,KAAO,iBAAiB,CACxC,OAAQC,OAAO,KAAO,UAAU,CAChC,OAAQC,WAAW,KAAO,eAAe,CAAC,2CAG1C,GAAML,QAAgB,CAAG,QAAnBA,QAAgB,EAAS,CAC3B,sBAAgBD,KAAK,CAACO,UAAU,CAACF,OAAO,CAAC,CAAlCG,KAAK,mBAALA,KAAK,CACZ,oBAAkCR,KAAK,CAACS,QAAQ,CAAoB,CAACC,KAAK,CAAE,EAAE,CAAC,CAAC,oDAAzEC,SAAS,qBAAEC,YAAY,qBAC9B,qBAAoCZ,KAAK,CAACS,QAAQ,CAAS,EAAE,CAAC,qDAAvDI,UAAU,qBAAEC,aAAa,qBAChC,qBAAwBd,KAAK,CAACS,QAAQ,CAACE,SAAS,CAACD,KAAK,CAAC,qDAAhDK,IAAI,qBAAEC,OAAO,qBACpB,qBAA4BhB,KAAK,CAACS,QAAQ,CAAU,KAAK,CAAC,qDAAnDQ,MAAM,qBAAEC,SAAS,qBAExBlB,KAAK,CAACmB,SAAS,CAAC,UAAM,CAClBX,KAAK,CAACY,eAAe,EAAE,CAACC,IAAI,CAAC,iBACzBH,UAAS,CAAC,IAAI,CAAC,GAClB,CACD;AACJ,CAAC,CAAE,EAAE,CAAC,CAENlB,KAAK,CAACmB,SAAS,CAAC,UAAM,CAClBP,YAAY,CAACJ,KAAK,CAACc,QAAQ,EAAE,CAAC,CAC9BX,SAAS,CAACD,KAAK,EAAIM,OAAO,CAACL,SAAS,CAACD,KAAK,CAAC,CAC3C;AACJ,CAAC,CAAE,CAACF,KAAK,CAACc,QAAQ,EAAE,C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